home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / URIUrlScheme.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  5.3 KB  |  237 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.plugin.PluginRegistry;
  4. import com.extensibility.plugin.api.URIScheme;
  5. import com.extensibility.plugin.api.URISchemeAdapter;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.OutputStream;
  9. import java.io.OutputStreamWriter;
  10. import java.io.Reader;
  11. import java.io.Writer;
  12. import java.net.HttpURLConnection;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLConnection;
  16.  
  17. public class URIUrlScheme extends URISchemeAdapter {
  18.    private URL url;
  19.  
  20.    public static void registerPlugin(PluginRegistry var0) {
  21.       var0.registerPlugin("URIScheme10", Class.forName("com.extensibility.xml.URIUrlScheme"), "URIUrlcheme", 65537);
  22.    }
  23.  
  24.    public URIUrlScheme() {
  25.       this.url = null;
  26.    }
  27.  
  28.    public URIUrlScheme(URL var1) {
  29.       this.url = var1;
  30.    }
  31.  
  32.    public void registerSchemes(URIScheme.Manager var1) {
  33.       var1.registerScheme("http", Class.forName("java.net.URL"), this);
  34.       var1.registerScheme("ftp", Class.forName("java.net.URL"), this);
  35.    }
  36.  
  37.    public URIScheme construct(String var1, String var2) {
  38.       URL var3 = null;
  39.  
  40.       try {
  41.          var3 = new URL(var2);
  42.       } catch (Exception var5) {
  43.       }
  44.  
  45.       return new URIUrlScheme(var3);
  46.    }
  47.  
  48.    public URIScheme construct(Object var1) {
  49.       return new URIUrlScheme((URL)var1);
  50.    }
  51.  
  52.    public URIScheme construct(String var1) {
  53.       URL var2 = null;
  54.  
  55.       try {
  56.          var2 = new URL(this.url, var1);
  57.       } catch (Exception var4) {
  58.       }
  59.  
  60.       return new URIUrlScheme(var2);
  61.    }
  62.  
  63.    public String computeRelative(URIScheme var1) {
  64.       URIUrlScheme var2 = (URIUrlScheme)var1;
  65.       URL var3 = var2.url;
  66.       String var4;
  67.       if (this.url.getProtocol().equals(var3.getProtocol()) && this.url.getHost().equals(var3.getHost()) && this.url.getPort() == var3.getPort()) {
  68.          String var5 = this.url.getFile();
  69.          String var6 = var3.getFile();
  70.          int var7 = 0;
  71.  
  72.          int var8;
  73.          for(var8 = var6.indexOf(var7, 47); var8 > 0 && var6.regionMatches(var7, var5, var7, var8 - var7 + 1); var8 = var6.indexOf(var7, 47)) {
  74.             var7 = var8 + 1;
  75.          }
  76.  
  77.          int var9 = var8;
  78.  
  79.          StringBuffer var10;
  80.          for(var10 = new StringBuffer(); var8 > 0; var8 = var6.indexOf(var8, 47)) {
  81.             var10.append("../");
  82.          }
  83.  
  84.          var10.append(var5.substring(var9));
  85.          var4 = var10.toString();
  86.       } else {
  87.          var4 = this.url.toExternalForm();
  88.       }
  89.  
  90.       return var4;
  91.    }
  92.  
  93.    public URIScheme toParent() {
  94.       String var1 = this.url.getFile();
  95.       int var2 = var1.lastIndexOf(47);
  96.       URL var3 = this.url;
  97.       if (var2 >= 0) {
  98.          var1 = var1.substring(var2 + 1);
  99.       }
  100.  
  101.       try {
  102.          var3 = new URL(this.url.getProtocol(), this.url.getHost(), this.url.getPort(), var1);
  103.       } catch (MalformedURLException var5) {
  104.       }
  105.  
  106.       return new URIUrlScheme(var3);
  107.    }
  108.  
  109.    public String getScheme() {
  110.       return this.url.getProtocol();
  111.    }
  112.  
  113.    public String getUIName() {
  114.       return this.url.toExternalForm();
  115.    }
  116.  
  117.    public long getLength() {
  118.       long var1 = -1L;
  119.  
  120.       try {
  121.          URLConnection var3 = this.url.openConnection();
  122.          var1 = (long)var3.getContentLength();
  123.       } catch (Exception var4) {
  124.       }
  125.  
  126.       return var1;
  127.    }
  128.  
  129.    public InputStream createInputStream() throws IOException {
  130.       return this.url.openConnection().getInputStream();
  131.    }
  132.  
  133.    public Reader createReader() throws IOException {
  134.       return new XMLReader(this.url.openConnection().getInputStream());
  135.    }
  136.  
  137.    public Writer createWriter() throws IOException {
  138.       return new OutputStreamWriter(this.createOutputStream());
  139.    }
  140.  
  141.    public OutputStream createOutputStream() throws IOException {
  142.       HttpURLConnection var1 = (HttpURLConnection)this.url.openConnection();
  143.       ((URLConnection)var1).setAllowUserInteraction(false);
  144.       var1.setRequestMethod("HEAD");
  145.       long var2 = ((URLConnection)var1).getDate();
  146.       int var4 = var1.getResponseCode();
  147.       if (var4 == 200) {
  148.          var1.disconnect();
  149.          var1 = (HttpURLConnection)this.url.openConnection();
  150.          ((URLConnection)var1).setDoOutput(true);
  151.          ((URLConnection)var1).setAllowUserInteraction(false);
  152.          var1.setRequestMethod("DELETE");
  153.          ((URLConnection)var1).connect();
  154.          var4 = var1.getResponseCode();
  155.       }
  156.  
  157.       var1.disconnect();
  158.       var1 = (HttpURLConnection)this.url.openConnection();
  159.       var1.setRequestMethod("PUT");
  160.       ((URLConnection)var1).setDoOutput(true);
  161.       ((URLConnection)var1).setAllowUserInteraction(false);
  162.       ((URLConnection)var1).connect();
  163.       OutputStream var5 = ((URLConnection)var1).getOutputStream();
  164.       if (var5 == null) {
  165.          throw new IOException();
  166.       } else {
  167.          return new WrapOutputStream(var5, var1);
  168.       }
  169.    }
  170.  
  171.    public boolean exists() {
  172.       try {
  173.          if (this.url == null) {
  174.             boolean var10 = false;
  175.             return var10;
  176.          } else {
  177.             HttpURLConnection var7 = (HttpURLConnection)this.url.openConnection();
  178.             if (var7 == null) {
  179.                boolean var9 = false;
  180.                return var9;
  181.             } else {
  182.                ((URLConnection)var7).setDoInput(true);
  183.                var7.setRequestMethod("HEAD");
  184.                ((URLConnection)var7).setDoOutput(false);
  185.                ((URLConnection)var7).setAllowUserInteraction(false);
  186.                ((URLConnection)var7).connect();
  187.                long var2 = ((URLConnection)var7).getDate();
  188.                int var4 = var7.getResponseCode();
  189.                var7.disconnect();
  190.                Object var8 = null;
  191.                if (var4 == 200) {
  192.                   boolean var11 = true;
  193.                   return var11;
  194.                } else {
  195.                   boolean var5 = false;
  196.                   return var5;
  197.                }
  198.             }
  199.          }
  200.       } catch (IOException var6) {
  201.          Object var1 = null;
  202.          boolean var3 = false;
  203.          return var3;
  204.       }
  205.    }
  206.  
  207.    public boolean equals(URIScheme var1) {
  208.       URIUrlScheme var2 = (URIUrlScheme)var1;
  209.       return this.url.sameFile(var2.url);
  210.    }
  211.  
  212.    public int compareTo(URIScheme var1) {
  213.       URIUrlScheme var2 = (URIUrlScheme)var1;
  214.       boolean var3 = this.url.sameFile(var2.url);
  215.       int var4 = 0;
  216.       if (!var3) {
  217.          var4 = this.url.toExternalForm().compareTo(var2.url.toExternalForm());
  218.       }
  219.  
  220.       return var4;
  221.    }
  222.  
  223.    public String getShortName() {
  224.       String var1 = this.url.getFile();
  225.       int var2 = var1 != null ? var1.lastIndexOf("/") : -1;
  226.       if (var2 >= 0) {
  227.          var1 = var1.substring(var2 + 1);
  228.       }
  229.  
  230.       return var1;
  231.    }
  232.  
  233.    public String getFullPath() {
  234.       return this.url.toExternalForm();
  235.    }
  236. }
  237.